package org.speedmall.core.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.speedmall.amount.api.AmountFeignClient;
import org.speedmall.amount.api.bo.AmountDecreaseBO;
import org.speedmall.core.bo.OrderCreateBO;
import org.speedmall.core.service.OrderService;
import org.speedmall.storage.api.ProductFeignClient;
import org.speedmall.storage.api.bo.ProductDecreaseBO;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author hujiaguo
 * @Package org.speedmall.core.service.impl
 * @date 2024/4/25 18:48:56
 */
@Slf4j
public class OrderServiceImpl implements OrderService {

    @Autowired
    private AmountFeignClient amountFeignClient;

    @Autowired
    private ProductFeignClient productFeignClient;
    @Override
    public String create(OrderCreateBO orderCreateBO) {
        log.info("订单服务：创建订单：{}", orderCreateBO);

        ProductDecreaseBO productDecreaseBO = new ProductDecreaseBO();
        productDecreaseBO.setProductId(orderCreateBO.getProductId());
        productDecreaseBO.setCount(orderCreateBO.getCount());
        productFeignClient.decreaseStorage(productDecreaseBO);

        AmountDecreaseBO amountDecreaseBO = new AmountDecreaseBO();
        amountDecreaseBO.setUserId(orderCreateBO.getUserId());
        amountDecreaseBO.setAmount(orderCreateBO.getAmount());
        amountFeignClient.decreaseMoney(amountDecreaseBO);

        return "创建订单成功";
    }
}
